﻿using System;
using System.ServiceModel;

namespace WcfDynamicProxy
{
    public class WcfQueryFactory<TService> : QueryFactory<TService>, IDisposable
        where TService : class
    {
        private readonly WcfChannelFactory<TService> channelFactory;

        public WcfQueryFactory(Func<Uri,Uri> addressTranformer)
            : this(new WcfChannelFactory<TService>(addressTranformer), TaskManager.Instance)
        {
        }

        public WcfQueryFactory(EndpointAddress address, TaskManager taskManager)
            : this(new WcfChannelFactory<TService>(address), taskManager)
        {
        }

        public WcfQueryFactory(string endpointConfigurationName, EndpointAddress address, TaskManager taskManager)
            : this(new WcfChannelFactory<TService>(endpointConfigurationName, address), taskManager)
        {            
        }

        public WcfQueryFactory(string endpointConfigurationName, TaskManager taskManager)
            : this(new WcfChannelFactory<TService>(endpointConfigurationName), taskManager)
        {
        }

        private WcfQueryFactory(WcfChannelFactory<TService> channelFactory, TaskManager taskManager)
            : base(channelFactory, taskManager)
        {
            this.channelFactory = channelFactory;
        }

        #region IDsposable

        public void Dispose()
        {
            channelFactory.Dispose();            
        }


        #endregion
    }
}